﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Subtle.Domain.Services.Interfaces;
using Subtle.Areas.Administration.ViewModels;
using Subtle.Controllers;

namespace Subtle.Areas.Administration.Controllers
{
	[Authorize]
    public class MediaController : BaseController
    {
		private IMediaService mediaService;

		/// <summary>
		/// Initializes a new Account Controller
		/// </summary>
		/// <param name="mediaService"></param>
		public MediaController(IMediaService mediaService)
		{
			this.mediaService = mediaService;
		}

        /// <summary>
        /// Administration/Media/Index
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }

		/// <summary>
		/// Administration/Media/Add
		/// </summary>
		/// <returns></returns>
		public ActionResult Add()
		{
			return View();
		}

		/// <summary>
		/// Administration/Media/Add
		/// </summary>
		/// <param name="mediaAddViewModel"></param>
		/// <returns></returns>
		[HttpPost]
		public ActionResult Add(MediaAddViewModel mediaAddViewModel)
		{
			if (ModelState.IsValid)
			{
				mediaAddViewModel.MediaUrl = Request.Url.GetLeftPart(UriPartial.Authority) + "/Media/" + mediaService.Save(mediaAddViewModel.GetMedia()).ToString();
			}
			return View(mediaAddViewModel);
		}
    }
}
